/**
 * @type notype
 */
export default class c_Document {
    /**
     * dom选择器
     */
    static document() {
        //@ts-ignore
        window.$ = (
            selector: string,
            one: boolean = true,
            context: Document = document
        ): Element | HTMLCollectionOf<Element> | (Element | HTMLCollectionOf<Element>)[] => {
            const splits = selector.split(' ')
            if (splits.length > 1) {
                let ctx = undefined as any
                for (let i = 0; i < splits.length; i++) {
                    const str = splits[i]
                    //@ts-ignore
                    const res = $(str, false, ctx)
                    ctx = splits.length - 1 != i ? res : one ? res[0] : res
                }
                return ctx
            } else {
                if (selector.charAt(0) === '#') {
                    return context.getElementById(selector.slice(1))
                } else {
                    let res: HTMLCollectionOf<Element> = null as any
                    if (selector.charAt(0) === '.') {
                        res = context.getElementsByClassName(selector.slice(1))
                    } else {
                        res = context.getElementsByTagName(selector)
                    }
                    if (one && res) return res[0]
                    else return res
                }
            }
        }
    }
}
